//
//  SMBTableView.swift
//  ShareMusic
//
//  Created by 胡岩 on 16/5/4.
//  Copyright © 2016年 胡岩. All rights reserved.
//

import UIKit
@objc protocol SMBTableViewDelegate {
    optional func tableViewTouchesBegan(tableView:UITableView, touches: Set<UITouch>, withEvent event: UIEvent?)
    optional func tableViewTouchesMoved(tableView:UITableView, touches: Set<UITouch>, withEvent event: UIEvent?)
    optional func tableViewTouchesEnded(tableView:UITableView, touches: Set<UITouch>, withEvent event: UIEvent?)
}
class SMBTableView: UITableView {
    var touchDelegate:SMBTableViewDelegate?
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)
        self.touchDelegate?.tableViewTouchesBegan?(self, touches: touches, withEvent: event)
    }
    
    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesMoved(touches, withEvent: event)
        self.allowsSelection = false
        self.scrollEnabled = false
        self.touchDelegate?.tableViewTouchesMoved?(self, touches: touches, withEvent: event)
    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesEnded(touches, withEvent: event)
        self.scrollEnabled = true
        self.allowsSelection = true
        self.touchDelegate?.tableViewTouchesEnded?(self, touches: touches, withEvent: event)
    }
    override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
        super.touchesCancelled(touches, withEvent: event)
        self.scrollEnabled = true
        self.allowsSelection = true
    }
}
